﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PluginInterface;
using mIRCx.IRC.Client.Engine;
using mIRCx.IRC.Client.Engine.Data;

namespace CSharpIrcBot.Module.ArmoryLookup
{
    public class ArmoryLookup : IPlugin
    {
        public ArmoryLookup() { }


        #region Plugin Required Information
        string myName = "Armory Lookup";
        string myDescription = "This module performs a lookup on the WoWArmory and sends the results to the user.";
        string myVersion = "1.0.0";
        string myAuthor = "Macros";
        IPluginHost myHost = null;
        IrcClient myIrcClient = null;

        public string Description
        {
            get { return myDescription; }
        }

        public string Name
        {
            get { return myName; }
        }

        public string Version
        {
            get { return myVersion; }
        }

        public string Author
        {
            get { return myAuthor; }
        }

        public IPluginHost Host
        {
            get
            {
                return myHost;
            }
            set
            {
                myHost = value;
                myIrcClient = myHost.IrcClient;
            }
        }

        public void Initialize()
        {
            myIrcClient.OnPrivateMessage += new PrivateMessageHandler( myIrcClient_OnPrivateMessage );
        }

       

        public void Dispose()
        {
            myIrcClient.OnPrivateMessage -= new PrivateMessageHandler( myIrcClient_OnPrivateMessage );
        }
        #endregion

        void myIrcClient_OnPrivateMessage( string userName, string channel, string data )
        {
            if( data.ToLower().StartsWith( "!armory" ) )
            {
                StringBuilder message = new StringBuilder();
                message.Append("PRIVMSG ");
                List<string> lookup = data.Split( ' ' ).ToList<string>();
                if( lookup.Count != 3 )
                {
                    char c = (char)2;
                    message.Append(channel);
                    message.Append(" :");
                    message.Append( c );
                    message.Append(userName);
                    message.Append( c );
                    message.Append(": Format for !armory is '!armory <Character> <Realm>'");
                    myIrcClient.SendServerData( message.ToString() );
                }
            }
        }
    }


}
